package com.codrim.cs.data.server.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class CostTimeMonitor {
    private static final Logger logger = LoggerFactory.getLogger("monitor");

    @Pointcut("execution(* com.codrim.cs.data..*.*(..))")
    private void pointCutMethod() {
    }

    //声明环绕通知
    @Around("pointCutMethod()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        long begin = System.currentTimeMillis();
        Object o = pjp.proceed();
        long end = System.currentTimeMillis();
        logger.info("{}: {}", pjp.getTarget().getClass() + "." + pjp.getSignature().getName(), (end - begin));
        return o;
    }
}

